/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.uuid.UUIDGenerator;
import cn.qidisoft.edu.hzjt.dao.ProjectMapper;
import cn.qidisoft.edu.hzjt.model.Project;
import cn.qidisoft.edu.hzjt.service.IProjectService;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: CatalogServiceImpl.java, v 0.1 2018年9月28日 上午9:17:27 Administrator hhl $
 */
@Service("projectService")
public class ProjectServiceImpl implements IProjectService {
    @Autowired
    private ProjectMapper crojectMapper;

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryList(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public List<Project> queryList(Project project) {
        try {
            return crojectMapper.queryList(project);

        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryByPK(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public Project queryByPK(Project project) {
        try {
            return crojectMapper.queryByPK(project);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#add(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public String add(Project project) {
        String uui = UUIDGenerator.genReqID();
        try {
            project.setProjectUui(uui);
            crojectMapper.add(project);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }

        return uui;
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#update(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void update(Project project) {
        try {
            crojectMapper.update(project);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#delete(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void delete(Project project) {
        try {
            crojectMapper.delete(project);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryPageList(cn.qidisoft.microClass.resource.model.basis.Catalog, cn.qidisoft.core.common.pagination.Page)
     */
    @Override
    public PaginationBean<Project> queryPageList(Project project, Page page) {
        try {

            int c = crojectMapper.queryPageListcount(project);
            int totalRecords = 0;
            totalRecords = (int) c;

            PaginationBean<Project> pageHolder = new PaginationBean<Project>(page, totalRecords);

            List<Project> resultList = crojectMapper.queryPageList(project,
                new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#validation(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public int validation(Project project) {
        try {
            return crojectMapper.validation(project);
        } catch (Exception e) {
            e.printStackTrace();
            return -99;
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.IProjectService#selectProjectByid(cn.qidisoft.edu.hzjt.model.Project)
     */
    @Override
    public List<Project> selectProjectByid(Project data1) {
        try {
            return crojectMapper.selectProjectByid(data1);

        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.IProjectService#getUserLevel(cn.qidisoft.edu.hzjt.model.Employee)
     */
    @Override
    public List<Project> getUserLevel(Project data) {
        try {
            return crojectMapper.getUserLevel(data);

        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

}
